#include "GeneralSettings.h"
#include <QSettings>

static const char* keyLanguage = "Language";
static const char* keyStyle = "Style";
static const char* keyFont = "Font";
static const char* groupKey = "Application";

GeneralSettings::GeneralSettings()
    : language("English")
    , style("Cleanlooks")
    , font("Segoe UI", 8)
{
}

void GeneralSettings::toSettings(QSettings *s) const
{
    s->beginGroup(groupKey);
    s->setValue(QLatin1String(keyLanguage), language);
    s->setValue(QLatin1String(keyStyle), style);
    s->setValue(QLatin1String(keyFont), QString("%1,%2").arg(font.family()).arg(font.pointSize()));
    s->endGroup();
}

void GeneralSettings::fromSettings(QSettings *s)
{
    *this = GeneralSettings(); // assign defaults

    s->beginGroup(groupKey);
    language = s->value(QLatin1String(keyLanguage), language).toString();
    style = s->value(QLatin1String(keyStyle), style).toString();
    font.fromString(s->value(QLatin1String(keyFont), font.toString()).toString());
    s->endGroup();
}

bool GeneralSettings::equals(const GeneralSettings &as) const
{
    return language == as.language
        && style == as.style
        && font == as.font;
}
